import dataPreferences from '@ohos.data.preferences';
class PreferencesUtil{
  preferences:dataPreferences.Preferences = null

  getPreferenceInstance(){
    return this.preferences;
  }

  async initPreference(context){
    this.preferences = await dataPreferences.getPreferences(context,'mystore')
  }
  async setPreference(key,value){
    await this.preferences.put(key,value)
    //持久化
    await this.preferences.flush()
  }

  getPreference(key,defaultValue:string = ''){
    return this.preferences.get(key,defaultValue)
  }
  async deletePreference(key){
    await this.preferences.delete(key)
  }
}
export default  new PreferencesUtil()